from openpyxl import Workbook
from utils.settings import URL_PREFIX
from utils.pivixitem import PivixItem


def get_start_url(urls):
    ret = []
    for u in urls:
        item = URL_PREFIX + u
        ret.append(item)
    return ret

def make_start_url(aid):
    return URL_PREFIX + aid

async def save_data(item:PivixItem):
    wb = Workbook()
    ws = wb.active
    ws['A1'] = 'artwork_id'
    #ws['B1'] = 'artist_id'
    #ws['C1'] = 'post_time'
    #ws['D1'] = 'tags'
    #ws['E1'] = 'like'
    #ws['F1'] = 'mark_num'
    ws['B1'] = 'mark_users'
    ws['C1'] = 'date'
    #ws['H1'] = 'views'
    for i in item.followers:
        name = i['follower']
        date = i['date']
        line = [item.aid, str(name), str(date)]
        ws.append(line)
    try:
        wb.save(f'{item.aid}.xlsx')
    except PermissionError as e:
        print(e)
    else:
        print(item.aid, ' save √! items = ', len(item.followers))